package org.uam.util.lock;

import org.uam.util.lock.service.LockRecharger;
import org.uam.util.lock.service.impl.LockRechargerImpl;

public class LockUtil
{
    LockRecharger lr = new LockRechargerImpl();
    /**
     * 充值锁
     *
     * @param userId 用户ID
     * @return isRechargeLocked isRechargeLocked
     * @throws Exception
     * @throws Exception
     * @see [类、类#方法、类#成员]
     */
    protected boolean lockRecharge(String userId) throws Exception
    {
        boolean isRechargeLocked = true;

        //锁定充值用户
//        LOG.info("lockRecharge begin", "userId", userId);
//        isRechargeLocked = ServiceUtil.getService(LockRecharger.class).lockRecharger(userId);
                isRechargeLocked = lr.lockRecharger(userId);
//        LOG.info("lockRecharge end");
        return isRechargeLocked;
    }

    /**
     * 充值解锁
     *
     * @param userId 用户ID
     * @see [类、类#方法、类#成员]
     */
    protected void unlockRecharge(String userId)
    {
        try
        {
            //为充值用户解锁
//            LOG.info("unlockRecharge begin", "userID", userId);
//            ServiceUtil.getService(LockRecharger.class).unlockRecharger(userId);
            lr.unlockRecharger(userId);
//            LOG.info("unlockRecharge end");
        }
        catch (Exception e)
        {
//            LOG.error("UnlockRecharge failed,but we should ignore it!Wait for the time task to clear the lock.",
//                e,
//                "userId",
//                userId);
            e.printStackTrace();
        }
    }
}
